package com.bluefoxyu.controller;

import com.bluefoxyu.domain.Result;
import com.bluefoxyu.service.DeepSeekService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;

@RestController
@RequestMapping("/api/chat")
public class ChatController {

    @Resource
    private DeepSeekService deepSeekService;

    @PostMapping("/one")
    public String chat(@RequestBody String message) {
        try {
            return Result.success(deepSeekService.sendMessage(message)).toJson();
        } catch (IOException e) {
            throw new RuntimeException("调用DeepSeek API失败: " + e.getMessage(), e);
        }
    }

    // 多轮对话
    // 目前还没做用户区分，不过数据表里面做了这个字段，到时候查询再加一层即可
    @PostMapping("/completion")
    public String chatCompletion(@RequestBody String param) {
        try {
            return Result.success(deepSeekService.chatCompletion(param)).toJson();
        } catch (IOException e) {
            throw new RuntimeException("调用DeepSeek API失败: " + e.getMessage(), e);
        }
    }
}